﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
#if NETFX_CORE
using Windows.ApplicationModel.Resources;

#endif

namespace StyleMVVM.Validation.Impl.Fluent.Operators
{
	public class IsTrueOrNullOperator<T> : UnaryOperator<T>
	{
		public IsTrueOrNullOperator()
		{
			expressionMethod = GetType().GetTypeInfo().GetDeclaredMethod("Operate");
		}

#if NETFX_CORE
		public override string GenerateLogicStatement(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "IsTrueOrNull");
		}

		public override string GenerateErrorMessage(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "MustBeTrueOrNull");
		}
#else
		public override string GenerateLogicStatement()
		{
			return InternalGenerateMessage(FluentResources.IsTrueOrNull);
		}

		public override string GenerateErrorMessage()
		{
			return InternalGenerateMessage(FluentResources.MustBeTrueOrNull);
		}
#endif

		public static bool Operate(object leftValue)
		{
			return leftValue == null || Equals(leftValue, true);
		}
	}
}